package com.zhw.controller;

import com.zhw.anno.Log;
import com.zhw.pojo.Dept;
import com.zhw.pojo.Result;
import com.zhw.service.DeptService;
import com.zhw.service.impl.DeptServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Scope("prototype")
@RestController
@Slf4j
public class DeptController {


    @Autowired
    DeptService dsi;



    //    获取所有部门的信息
    @GetMapping("/depts")
    public Result getDept() {
        log.info("查询所有员工信息");
        List<Dept> list = dsi.getDept();


        return Result.success(list);
    }

       public Result newMethod3() {
        log.info("查询所有员工信息");
        List<Dept> list = dsi.getDept();


        return Result.success(list);
    }





    //    删除某个部门
    @Log
    @DeleteMapping("/depts/{id}")
    public Result delete(@PathVariable Integer id) {
        dsi.delete(id);

        log.info("ID号为{}的部门以及移除", id);




        return Result.success();

    }

    //    新增某个部门
    @Log
    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept) {
        dsi.add(dept);
        log.info("新用户成功");
        return Result.success();

    }



//    根据ID查询某个部门
    @GetMapping("/depts/{id}")
    public Result selectById(@PathVariable Integer id){
        Dept dept=dsi.selectById(id);
        return Result.success(dept);
    }

//      修改部门信息
    @Log
    @PutMapping("/depts")
    public Result update(@RequestBody Dept dept){
    dsi.update(dept);
    return Result.success();
    }







}
